package cn.iocoder.yudao.module.member.convert.auth;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.dal.dataobject.auth.MemberShopAuthDO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.userdetail.vo.UserDetailCreateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.member.controller.admin.auth.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.auth.MemberAuthDO;

/**
 * 会员认证大愚灸术学员 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface MemberAuthConvert {

    MemberAuthConvert INSTANCE = Mappers.getMapper(MemberAuthConvert.class);

    MemberAuthDO convert(MemberAuthCreateReqVO bean);

    MemberAuthDO convert(MemberAuthUpdateReqVO bean);

    default MemberAuthRespVO convert(MemberAuthDO bean){
        if ( bean == null ) {
            return null;
        }

        MemberAuthRespVO memberAuthRespVO = new MemberAuthRespVO();

        memberAuthRespVO.setMemberId( bean.getMemberId() );
        memberAuthRespVO.setReason( bean.getReason() );
        memberAuthRespVO.setPicUrl( bean.getPicUrl() );
        memberAuthRespVO.setLearnTime( bean.getLearnTime() );
        memberAuthRespVO.setRealName( bean.getRealName() );
        memberAuthRespVO.setIdNumber( bean.getIdNumber() );
        memberAuthRespVO.setIdFront( bean.getIdFront() );
        memberAuthRespVO.setIdBack( bean.getIdBack() );
        memberAuthRespVO.setId( bean.getId() );
        memberAuthRespVO.setStatus( bean.getStatus() );
        memberAuthRespVO.setCreateTime( bean.getCreateTime() );
        memberAuthRespVO.setAreaId(bean.getAreaId());

        memberAuthRespVO.setAreaName(AreaUtils.format(bean.getAreaId()));

        return memberAuthRespVO;
    }

    List<MemberAuthRespVO> convertList(List<MemberAuthDO> list);

    PageResult<MemberAuthRespVO> convertPage(PageResult<MemberAuthDO> page);

    List<MemberAuthExcelVO> convertList02(List<MemberAuthDO> list);

    default MemberShopAuthRespVO convertShop(MemberShopAuthDO bean){
        if ( bean == null ) {
            return null;
        }

        MemberShopAuthRespVO memberShopAuthRespVO = new MemberShopAuthRespVO();

        memberShopAuthRespVO.setId(bean.getId());
        memberShopAuthRespVO.setMemberId(bean.getMemberId());
        memberShopAuthRespVO.setStatus(bean.getStatus());
        memberShopAuthRespVO.setCreateTime(bean.getCreateTime());
        memberShopAuthRespVO.setReason(bean.getReason());
        memberShopAuthRespVO.setPicUrl(bean.getPicUrl());
        memberShopAuthRespVO.setShopName(bean.getShopName());
        memberShopAuthRespVO.setAddress(bean.getAddress());
        memberShopAuthRespVO.setDescription(bean.getDescription());
        memberShopAuthRespVO.setTitleUrl(bean.getTitleUrl());
        memberShopAuthRespVO.setAreaId(bean.getAreaId());
        memberShopAuthRespVO.setAreaName(AreaUtils.format(bean.getAreaId()));
        memberShopAuthRespVO.setSize(bean.getSize());
        memberShopAuthRespVO.setRoomCount(bean.getRoomCount());
        memberShopAuthRespVO.setJiushiCount(bean.getJiushiCount());
        memberShopAuthRespVO.setVideoUrl(bean.getVideoUrl());

        return memberShopAuthRespVO;
    }

    default List<MemberShopAuthRespVO> convertShopList(List<MemberShopAuthDO> list){
        if ( list == null ) {
            return null;
        }

        List<MemberShopAuthRespVO> list1 = new ArrayList<MemberShopAuthRespVO>( list.size() );
        for ( MemberShopAuthDO memberShopAuthDO : list ) {
            list1.add( convertShop( memberShopAuthDO ) );
        }

        return list1;
    }

    default PageResult<MemberShopAuthRespVO> convertShopPage(PageResult<MemberShopAuthDO> page){
        if ( page == null ) {
            return null;
        }

        PageResult<MemberShopAuthRespVO> pageResult = new PageResult<MemberShopAuthRespVO>();

        pageResult.setList( convertShopList( page.getList() ) );
        pageResult.setTotal( page.getTotal() );

        return pageResult;
    }

    default UserCreateReqVO convertUserVO(MemberAuthDO memberAuthDO, MemberUserRespDTO memberUserRespDTO, String password) {
        UserCreateReqVO vo = new UserCreateReqVO();
        vo.setPassword(password);
        vo.setUsername(memberUserRespDTO.getMobile());
        vo.setAvatar(memberUserRespDTO.getAvatar());
        vo.setEmail("");
        vo.setMobile(memberUserRespDTO.getMobile());
        vo.setNickname(memberUserRespDTO.getNickname());
        vo.setPostIds(new HashSet<>());
        vo.setRemark("会员认证");

        return vo;
    }

    default UserDetailCreateReqVO convertDetailUserVO(AdminUserDO userDO, MemberAuthDO memberAuthDO){
        UserDetailCreateReqVO vo = new UserDetailCreateReqVO();

        vo.setUserId(userDO.getId());
        vo.setMobile(userDO.getMobile());
        vo.setIdNumber(memberAuthDO.getIdNumber());
        vo.setIdFront(memberAuthDO.getIdFront());
        vo.setIdBack(memberAuthDO.getIdBack());
        vo.setLearnTime(memberAuthDO.getLearnTime());
        vo.setRealName(memberAuthDO.getRealName());
        vo.setPicUrl(memberAuthDO.getPicUrl());
        vo.setAreaId(memberAuthDO.getAreaId());

        return vo;
    }

}
